public class Main {

    public static int qiuzuida(int[] nums) {
        if (nums == null || nums.length == 0) {
            return 0;
        }

        int max1 = nums[0];
        int max2 = nums[0];

        for (int i = 1; i < nums.length; i++) {

            max2 = Math.max(nums[i], max2 + nums[i]);
            max1 = Math.max(max1, max2);
        }

        return max1;
    }

    public static void main(String[] args) {
        int[] nums1 = {1, -2, 3, 5, -1};
        System.out.println("最大和: " + qiuzuida(nums1));

        int[] nums2 = {1, -2, 3, -8, 5, 1};
        System.out.println("最大和: " + qiuzuida(nums2));

        int[] nums3 = {1, -2, 3, -2, 5, 1};
        System.out.println("最大和: " + qiuzuida(nums3));
    }
}